H=localhost

install: #st1+ install ansible tool #
	@yum -y install $(roleHome)/files/ansible-2.9.9-1.el7.ans.noarch.rpm

initEnv: #st2+ new Inventory #D=? //根域
	@$(scriptsDir)/assertx.sh NotNull D ${D}
	@$(scriptsDir)/ensurex.sh xDir ~/.envs/ansible \
	&& cat ${roleHome}/hosts/hosts.yaml > ~/.envs/ansible/hosts.yaml \
	&& sed -i 's/{{domain}}/${D}/g' ~/.envs/ansible/hosts.yaml \
	&& cat ~/.envs/ansible/hosts.yaml

newCtx: #新建一个上下文  #N=?//英文名  D=? //根域
	@$(scriptsDir)/assertx.sh NotNull N ${N}
	@$(scriptsDir)/assertx.sh NotNull D ${D}
	@$(scriptsDir)/ensurex.sh xDir ~/.envs/ansible \
	&& cat ${roleHome}/hosts/hosts.yaml > ~/.envs/ansible/ctx/${N}.yaml \
	&& sed -i 's/{{domain}}/${D}/g' ~/.envs/ansible/ctx/${N}.yaml \
	&& cat ~/.envs/ansible/ctx/${N}.yaml

initRole: #optional- new Ansible role #R=? //Role Name, E=? //envs eg:pass:123\ndebug:true
	${scriptsDir}/assertx.sh NotNull R ${R}
	ansible-galaxy init roles/${R} \
	&& cat ${roleHome}/roots/play-book.yaml > $(CURDIR)/roles/${R}/play-book.yaml \
	&& sed -i 's/{{Role}}/${R}/g' $(CURDIR)/roles/${R}/play-book.yaml \
	&& cat ${roleHome}/roots/Makefile > $(CURDIR)/roles/${R}/Makefile-${R}.mk \
	&& cat ${roleHome}/tasks/tpl.yml > $(CURDIR)/roles/${R}/tasks/tpl.yml \
	&& cat ${roleHome}/tasks/main.yml > $(CURDIR)/roles/${R}/tasks/main.yml \
	&& sed -i 's/{{Role}}/${R}/g' $(CURDIR)/roles/${R}/tasks/main.yml \
	&& cat ${roleHome}/templates/Makefile.mk > $(CURDIR)/roles/${R}/templates/Makefile \
	&& cat ${roleHome}/templates/run.sh > $(CURDIR)/roles/${R}/templates/run.sh
	${scriptsDir}/helpx.sh setVars "${E}" "$(CURDIR)/roles/${R}/vars/main.yml"

newRole: #optional- new Ansible role #R=? //Role Name, E=? //envs eg:pass:123\ndebug:true
	${scriptsDir}/assertx.sh NotNull R ${R}
	ansible-galaxy init roles/${R} \
	&& cat ${roleHome}/roots/play-book.yaml > $(CURDIR)/roles/${R}/play-book.yaml \
	&& sed -i 's/{{Role}}/${R}/g' $(CURDIR)/roles/${R}/play-book.yaml \
	&& cat ${roleHome}/roots/Makefile-v2 > $(CURDIR)/roles/${R}/Makefile-${R}.mk \
	&& cat ${roleHome}/tasks/tpl.yml > $(CURDIR)/roles/${R}/tasks/tpl.yml \
	&& cat ${roleHome}/tasks/main-v2.yml > $(CURDIR)/roles/${R}/tasks/main.yml \
	&& sed -i 's/{{Role}}/${R}/g' $(CURDIR)/roles/${R}/tasks/main.yml \
	&& cp -R ${roleHome}/tasks/children/*  $(CURDIR)/roles/${R}/tasks 
	${scriptsDir}/helpx.sh setVars "${E}" "$(CURDIR)/roles/${R}/vars/main.yml"



	

